<?php
namespace common\models\trade;
use common\models\BaseModel;
use common\models\finance\BalanceTypeModel;
/*
	兑换配置表

*/

class TradeExchangeModel extends BaseModel
{

	public static function tableName()
	{
		return '{{%trade_exchange}}';
	}

	public function rules()
	{
		return [
			[['b_type2','b_type1','mch_id','rate','multiple','min_num','max_num','num_times','next_action','state','create_time'],'number']
		];
	}


	public static function getConf($btype1,$btype2)
	{
		$where = ['b_type1'=>$btype1,'b_type2'=>$btype2,'mch_id'=>MCHID];
		$conf = self::find()->where($where)->asarray()->one();
		if(!$conf) return false;

		$type1 = BalanceTypeModel::find()->where(['type'=>$btype1])->asarray()->one();
		if(!$type1) return false;

		$type2 = BalanceTypeModel::find()->where(['type'=>$btype2])->asarray()->one();
		if(!$type2) return false;

		$conf['price1'] = $type1['price'];
		$conf['price2'] = $type2['price'];
		return $conf;
	}


}